import com.hx.config.SpringConfig;
import com.hx.dao.UserDao;
import com.hx.pojo.User;
import com.mysql.cj.util.DnsSrv;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class TextUser {
    @Test
    public void m1(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        User user = new User();
        user.setId(null);
        user.setUname("类咧咧");
        user.setUpwd("987");
        user.setUaddr("北京");
        user.setUtel("1112445454");
        userDao.add(user);
    }
    @Test
    public void m2(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        User user = new User();
        user.setId(4);
        user.setUname("咧咧");
        user.setUpwd("87");
        user.setUaddr("京");
        user.setUtel("2445454");
        userDao.update(user);
    }
    @Test
    public void m3(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        userDao.delete(3);
    }
    @Test
    public void m4(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
         User user= userDao.selectUserById(5);
        System.out.println(user);
    }
    @Test
    public void m5(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        userDao.getAll();
    }
    @Test
    public void m6(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        List<User> list=userDao.findAllUser();
        list.forEach(user -> System.out.println(user));
    }
    @Test
    public void m7(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        ArrayList<Object[]> list = new ArrayList<>();
        Object[] object1 = new Object[]{"小子","123","数据","1234556564"};
        Object[] object2 = new Object[]{"小子","123","数据","1234556564"};
        Object[] object3 = new Object[]{"小子","123","数据","1234556564"};
        list.add(object1);
        list.add(object2);
        list.add(object3);
        userDao.batchAddUser(list);
    }
    @Test
    public void m8(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserDao userDao = context.getBean(UserDao.class);
        ArrayList<Object[]> list = new ArrayList<>();
        Object[] object1 = new Object[]{"小子","1723","数据","123455564",1};
        Object[] object2 = new Object[]{"小子","123","数据","1235656",2};
        Object[] object3 = new Object[]{"小子","13","数据","1256564",4};
        list.add(object1);
        list.add(object2);
        list.add(object3);
        userDao.batchupdateUser(list);

    }
    @Test
    public void m9(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        final UserDao userDao = context.getBean(UserDao.class);
        final ArrayList<Object[]> list = new ArrayList<>();
        final Object[] Object1 = new Object[]{11};
        final Object[] Object2 = new Object[]{12};
        final Object[] Object3 = new Object[]{13};
        list.add(Object1);
        list.add(Object2);
        list.add(Object3);
        userDao.batchdelete(list);

    }
    @Test
    public void m10(){
        //获取容器，加载配置类
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        //获取bean对象
        final UserDao userDao = context.getBean(UserDao.class);
        List<Object[]> list = new ArrayList<>();
        list.add(new Object[]{});
    }
}
